package services

import (
	"net/http"

	"github.com/gin-gonic/gin"

	models "learn/models"
)

//	@Tags		测试方法
//
// @Summary 	 Ping列表
// @Router		/r/ping [get]
// @Produce json
// @Param id path int true "文章ID"
func Ping(c *gin.Context) {
	c.JSON(http.StatusOK, gin.H{
		"code": "200",
		"data": map[string]interface{}{
			"data": "hello world",
		},
	})
}

//	@Tags		用户相关接口
//
// @Summary 	 获取用户泪飙
// @Router		/user/getUsersList [get]
// @Produce json
// @Param pageSize path int true "页码"
// @Param pageNo path int true "数量"
func GetUsersList(c *gin.Context) {
	var users []models.UserBasic
	tx2 := models.DB.Table("user_basic").Limit(10).Find(&users)
	c.JSON(http.StatusOK, gin.H{
		"code": "200",
		"data": map[string]interface{}{
			"list":  users,
			"count": tx2.RowsAffected,
		},
	})
}

func AddUserInfo(c *gin.Context) {
	username := c.PostForm("username")
	password := c.PostForm("password")
	nickname := c.PostForm("nikeName")
	tel := c.PostForm("tel")

	insertUser := models.UserBasic{
		Username: username,
		Password: password,
		NickName: nickname,
		Tel:      tel,
	}

	tx2 := models.DB.Table("user_basic").Create(&insertUser)
	c.JSON(http.StatusOK, gin.H{
		"code": "200",
		"data": map[string]interface{}{
			"username": username,
			"password": password,
			"allData":  tx2,
		},
	})
}
